#import "smcTextField.h"

@implementation smcTextField

- (id) initWithFrame: (CGRect) rect
{
	self = [super initWithFrame: rect];
	if (self != nil) 
	{
		[self setFont: [NSClassFromString(@"WebFontCache") createFontWithFamily:@"Helvetica" traits:0 size:14.0f]];		
		[self setLabel: @"from"];
		[self setVerticallyCenterText: YES];
		[self setPaddingLeft: 20.0f];
		[self setBackgroundColor: [UIView colorWithRed: 0.95f green: 0.95f blue: 0.95f alpha: 1.0f]];
		[self setPlaceholder: @"my iPhone"];
		[self setTapDelegate: self];
	}
	return self;
}

#pragma mark Subclass! Not! Delegated!

- (BOOL)fieldEditor:(id)fp8 shouldInsertText:(id) insert replacingRange:(struct _NSRange)fp16
{
	if ([insert isEqualToString: @"\n"])
	{NSLog (@"IIII");
		if ([[self delegate] respondsToSelector: @selector(textViewReturnWithoutAllowance:)])
			[[self delegate] performSelector: @selector(textViewReturnWithoutAllowance:) withObject: self];
		return NO;
	} else
		return [super fieldEditor: fp8 shouldInsertText: insert replacingRange: fp16];	
}

#pragma mark Tap delegate

- (BOOL)view:(id)view handleTapWithCount: (int) count event: (struct __GSEvent *) event
{
	// show keyboard if single tap in view
	// hide when double tapped

	if (count == 2)
	{
		if ([[self delegate] respondsToSelector: @selector(shouldHideKeyboardForView:)])
			[[self delegate] performSelector: @selector(shouldHideKeyboardForView:) withObject: self];
	} 
	else if ([[self delegate] respondsToSelector: @selector(shouldShowKeyboardForView:)])
			[[self delegate] performSelector: @selector(shouldShowKeyboardForView:) withObject: self];
			
	return YES;
}


@end
